package com.pivotal.cloud.security.jwt;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @className: com.pivotal.cloud.security.jwt.HeaderParameters
 * @projectName: 项目
 * @module: 项目-HeaderParameters类，主要位于模块
 * @content:
 * @author: Powered by Marklin
 * @datetime: 2025-06-21 20:35
 * @version:
 * @copyright: Copyright © 2018-2025 Systems Incorporated. All rights reserved.
 */
public class HeaderParameters {

	final String alg;

	final Map<String, String> map;

	final String typ;

	HeaderParameters(String alg) {
		this((Map) (new LinkedHashMap(Collections.singletonMap("alg", alg))));
	}

	HeaderParameters(Map<String, String> map) {
		this.typ = "JWT";
		String alg = (String) map.get("alg");
		String typ = (String) map.get("typ");
		if (typ != null && !"JWT".equalsIgnoreCase(typ)) {
			throw new IllegalArgumentException("typ is not \"JWT\"");
		}
		else {
			map.remove("alg");
			map.remove("typ");
			this.map = map;
			if (alg == null) {
				throw new IllegalArgumentException("alg is required");
			}
			else {
				this.alg = alg;
			}
		}
	}

}
